package com.yaoyong.yy_demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * 广播式
 */
@Configuration
@EnableWebSocketMessageBroker//1.开启使用STOMP协议传输消息,这时控制器支持使用@MessageMapping,和@RequestMapping一样
public class WebsocketConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {//2.注册协议的节点并映射的指定的url
        registry.addEndpoint("/endpointWisely").withSockJS();//注册一个endpoint,并指定使用SockJS协议
        registry.addEndpoint("/endpointChat").withSockJS();//注册一个endpoint,并指定使用SockJS协议
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {//配置消息代理
        registry.enableSimpleBroker("/queue", "/topic");//广播式配置一个/topic消息代理,点对点式增加一个/queue代理
    }
}
